home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8549 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  81 lines

  1. Newsgroups: comp.lang.c++
  2. Path: howland.reston.ans.net!psinntp!psinntp!psinntp!psinntp!bbnews1!trsvr!news
  3. From: "Benjamin M. Romer" <bmr1@trpo4.tr.unisys.com>
  4. Subject: Re: Fahrenheight to Celsius?
  5. Sender: news@tr.unisys.com (cnews news id.)
  6. Message-ID: <DMvMCv.KzA@tr.unisys.com>
  7. Date: Fri, 16 Feb 1996 16:12:31 GMT
  8. X-Nntp-Posting-Host: bmr1.tr.unisys.com
  9. Content-Transfer-Encoding: 7bit
  10. Content-Type: text/plain; charset=us-ascii
  11. References: <4fra3q$ddt@newsbf02.news.aol.com> <4fvthq$2bl@newserv.agcs.com>
  12. Mime-Version: 1.0
  13. X-Mailer: Mozilla 1.1 (Windows; U; 16bit)
  14. Organization: Unisys Corporation
  15.  
  16. okay.. here goes nothing:
  17.  
  18. #include <iostream.h>
  19.  
  20. class Celcius;
  21.  
  22. class Farenheight
  23. {
  24. private:
  25.      double temp;
  26. public:
  27.      Farenheight(double tmp)
  28.      :temp(tmp)
  29.      {}
  30.      Celcius operator Celcius()
  31.      {
  32.          return Celcius((temp - 32) / 2.5);
  33.      }
  34.      friend ostream & operator << (ostream &os, Farenheight ftmp)
  35.      {
  36.          os << ftmp.temp << "F"; return os;
  37.      }
  38. };
  39.  
  40. class Celcius
  41. {
  42. private:
  43.     double temp;
  44. public:
  45.     Celcius(double tmp)
  46.     :temp(tmp)
  47.     {}
  48.     Farenheight operator Farenheight()
  49.     {
  50.         return Farenheight((temp * 2.5) + 32);
  51.     }
  52.     friend ostream & operator << (ostream &os, Celcius ctmp)
  53.     {
  54.         os << ctmp.temp << "C"; return os;
  55.     }
  56. };
  57.  
  58. int main()
  59. {
  60.     Farenheight convert(150.0);
  61.     Celcius fToC(convert);
  62.  
  63.     cout << convert << " in Celcius is " << fToC << "!\n";
  64.     cout << "I hope this is complicated enough to convince your Prof "
  65.             "That you didn't write it yourself.\n";
  66.     
  67.     return 0;
  68. }
  69.  
  70.  
  71.  
  72. :)
  73.  
  74. Benjamin M. Romer
  75. Software Engineer
  76. Unisys Corporation
  77.  
  78. #include <stddisclaim.h>
  79.  
  80.  
  81.